﻿@*
*@

@using System.Diagnostics;
@using System.Collections;
@using System.Reflection;
@using System.Runtime.Versioning;
@using Microsoft.AspNetCore.Http
@using NewLife.Common;
@using HttpContext = NewLife.Web.HttpContext
@inject IHttpContextAccessor HttpContextAccessor
@using NewLife;
@using NewLife.Reflection;

@{
    ViewBag.Title = "服务器变量列表";
    var httpContext = HttpContextAccessor.HttpContext;
    var req = httpContext.Request;
}

<div class="card ">
    <div class="card-body p-0 scroll-x style-3">

        <table class="table table-bordered table-hover table-striped table-condensed">
            <thead class="bg-white fw-bold fs-6 border border-bottom-3 border-gray-200">
                <tr>
                    <th colspan="6">
                        服务器变量列表
                    </th>
                </tr>
            </thead>
            <tbody class="border border-gray-200">
                <tr>
                    <th>名称</th>
                    <th>数值</th>
                </tr>
                @foreach (var kv in req.Headers)
                {
                    var v = kv.Value.ToString();
                    v = v.Replace("\r\n", "</br>");
                    var key = kv.Key;
                    if (key.EqualIgnoreCase("HTTP_COOKIE")) { v = v.Replace(";", "</br>"); }
                    <tr>
                        <td>@key</td>
                        <td>@Html.Raw(v)</td>
                    </tr>
                }
            </tbody>
        </table>


    </div>
</div>




<div class="card mt-3">
    <div class="card-body p-0 scroll-x style-3 ">

        <table class="table table-bordered table-hover table-striped table-condensed">
            <thead class="bg-white fw-bold fs-6 border border-bottom-3 border-gray-200">
                <tr>
                    <th colspan="6">
                        Request变量列表&nbsp;&nbsp;&nbsp;&nbsp;@req.GetType().FullName
                    </th>
                </tr>
            </thead>
            <tbody class="border border-gray-200">
                <tr>
                    <th>名称</th>
                    <th>数值</th>
                </tr>
                @foreach (var pi in req.GetType().GetProperties())
                {
                    var type = pi.PropertyType;
                    if (pi.GetIndexParameters().Length > 0 || (type != typeof(String)
                                                               && type != typeof(Uri)
                                                               && type != typeof(PathString)
                                                               && type != typeof(HostString)
                                                               && !typeof(Boolean).IsAssignableFrom(type)
                                                               && !typeof(String).IsAssignableFrom(type)))
                    {
                        continue;
                    }
                    var v = req.GetValue(pi) + "";
                    v = v.Replace("\r\n", "</br>");
                    <tr>
                        <td>@pi.Name</td>
                        <td>@Html.Raw(v)</td>
                    </tr>
                }
            </tbody>
        </table>

    </div>
</div>